export const demo1 = `<div class="demo">
  <div class="js1-main-button">
    <button @click="randomColor">随机颜色1</button>
    <button @click="randomColor2">随机颜色2</button>
    <button @click="end">停止</button>
  </div>
  <div ref="randomColor" class="randomColor randomDiv">随机颜色1</div>
  <div ref="randomColor2" class="randomColor2 randomDiv">随机颜色2</div>
</div>
-----js-----
end(){
  clearTimeout(this.timerId1);
  clearTimeout(this.timerId2);
},

randomNumber(){
  return Math.floor(Math.random() * 256)
},

randomColor(){
  let r = this.randomNumber(),
      g = this.randomNumber(),
      b = this.randomNumber();
  this.timerId1 = setTimeout(()=>{
    this.$refs.randomColor.style.background = rgb(\${r},\${g},\${b})
    this.randomColor()
  },0)
},

randomColor2(){
  let rgb = ('#'+Math.random().toString(16).substring(2, 8))
  this.timerId2 = setTimeout(()=>{
    this.$refs.randomColor2.style.background = rgb
    this.randomColor2()
  },0)
}
`

export const demo2 = `<div class="demo" ref="demo">
  <div class="js2-main-button">
    <el-button type="primary" @click="Lockbattery">查看电池信息</el-button>
  </div>
  <div class="batteryMain">
    <p>当前电量：<span>{{level}}</span></p>
    <p>电池剩余可用时间：<span>{{dischargingTime}}</span></p>
    <p>充满需要多久：<span>{{chargingTime}}</span>分钟</p>
    <p>是否在充电：<span>{{charging | isBooler}}</span></p>
  </div>
</div>
-----js-----
Lockbattery(){
  navigator.getBattery().then((battery)=>{
    this.charging = battery.charging
    this.chargingTime = battery.chargingTime
    this.dischargingTime = battery.dischargingTime == Infinity?'此电脑为台式机，只要通电就可一直使用': battery.dischargingTime
    this.level = battery.level*100%
    battery.addEventListener("levelchange", function () {
      // 电量改变时触发该监听函数
      console.log(battery)
    });

    battery.addEventListener("chargingchange", function () {
      // 充电状态改变时触发该监听函数
      console.log(battery)
    }, false);

    battery.addEventListener("chargingtimechange", function () {
      // 充满还需时间改变时触发该监听函数
      console.log(battery)
    }, false);

    battery.addEventListener("dischargingtimechange", function () {
      // 电池剩余可用时间改变时触发该监听函数
      console.log(battery)
    }, false);
  })
}
`